let { salespersonsModel } = require('./models/salespersonsModel');
let { usersModel } = require('./models/usersModel');
//获取操作流水
module.exports.getSalespersons = async function () {
    let data = await salespersonsModel.find();
    return data;
}
//新增销售员
module.exports.addSalespersons = async function ({ salesName, salesAccount, salesPassword, salesPhone }) {
    let data = await salespersonsModel.create({ salesName, salesAccount, salesPassword, salesPhone });
    return data;
}
// 修改销售员信息
module.exports.updateSalespersons = async function ({ _id, salesName, salesAccount, salesPassword, salesPhone }) {
    let data = await salespersonsModel.updateOne({ _id }, { salesName, salesAccount, salesPassword, salesPhone })
    return data;
}
//删除销售员信息
module.exports.deleteSalespersons = async function (result) {
    let data = await salespersonsModel.deleteOne(result)
    return data;
}
//查看该销售员负责的客户列表
module.exports.getCustomerList = async function () {
    let data = await salespersonsModel.aggregate([
        //关联查询
        {
            $lookup: {
                from: 'users',
                localField: '_id',
                foreignField: 'salespersonsId',
                as: 'usersResult'
            },
        },
    ])
    return data;
}
//查看该销售员负责的客户列表List
module.exports.getCustomerList1 = async function (result) {
    let data = await usersModel.find(result)
    return data;
}

//获取某一个销售员的信息
module.exports.getPersonOne = async function (result) {
    return await salespersonsModel.find(result)
}